<?php
/*
数据库类

*/
namespace  APP\db;
class Db{
	private $conn;
	private $query;
	static $instance;

	public function __construct($dbHost,$dbUser,$dbPwd,$dbName){
		$this->conn = mysqli_connect($dbHost, $dbUser, $dbPwd, $dbName);
		if($this->conn && (empty($this->conn->connect_errno)) ){
	 		$result  =  mysqli_query( $this->conn,"set names utf8;"); 
			if($result){
				return true;			
			}
		}
		return false;
	}


	public static function get_instance($dbHost,$dbUser,$dbPwd,$dbName){
		if(!(self::$instance instanceof self))
		{
			self::$instance=new self($dbHost,$dbUser,$dbPwd,$dbName);
		
		}
		return self::$instance;
	}

    public function query($sql)
	{
		$query=mysqli_query($this->conn,$sql);
		$this->query = $query;
		return $this;
		
	}




	public function upCheck(){
		return $this->query;
	}


    public function fetch_array()
	{
	  	$query_arr=array();	
		// $row=mysqli_fetch_array($this->query,MYSQL_ASSOC); 
		 if(  mysqli_num_rows ( $this->query ) >0 ){
		 	while(	$row=mysqli_fetch_array($this->query,MYSQL_ASSOC)	){
		 		// $query_arr[]=$row;
		 		array_push($query_arr,$row);
		 	}

		 	return $query_arr;
		 }else{

		 	return false;


		 }
		 

	}




}





?>